package com.example.demo.service;

import com.example.demo.entity.NoteComment;
import com.example.demo.entity.NoteCreate;
import com.example.demo.mapper.NoteCommentMapper;
import com.example.demo.vo.ViewNoteCommentInfo;
import com.example.demo.vo.ViewNoteCreateInfo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoteCommentImpl implements NoteCommentService {
    @Autowired
    private NoteCommentMapper noteCommentMapper;

    @Override
    public PageInfo<ViewNoteCommentInfo> findNoteCommentInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ViewNoteCommentInfo> list = noteCommentMapper.findNoteCommentInfo();
        PageInfo<ViewNoteCommentInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public PageInfo<NoteComment> findNoteCommentPages(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<NoteComment> lists = noteCommentMapper.findNoteCommentAll();
        PageInfo<NoteComment> pageInfo = new PageInfo<>(lists);  //构造函数，传递函数
        return pageInfo;   //返回pageInfo
    }

    @Override
    public ViewNoteCommentInfo findNoteCommentById(Integer note_comment_id) {
        return noteCommentMapper.findNoteCommentInfoId(note_comment_id);
    }

    @Override
    public List<NoteComment> findNoteCommentAll(){
        return noteCommentMapper.findNoteCommentAll();
    }

    @Override
    public NoteComment findNoteCommentDyId(Integer note_comment_id) {
        return noteCommentMapper.findNoteCommentDyId(note_comment_id);
    }

    @Override
    public Integer insertNoteComment(NoteComment noteComment) {
        return noteCommentMapper.insertNoteComment(noteComment);
    }

    @Override
    public Integer updateNoteComment(NoteComment noteComment) {
        return noteCommentMapper.updateNoteComment(noteComment);
    }

    @Override
    public Integer deleteNoteComment(Integer note_comment_id) {
        return noteCommentMapper.deleteNoteComment(note_comment_id);
    }






    //与用户表的用户名、头像相关联，且根据笔记id查找，按点赞量排序
    @Override
    public PageInfo<ViewNoteCommentInfo> findNoteCommentInfonoteid(Integer note_create_id) {
        List<ViewNoteCommentInfo> list = noteCommentMapper.findNoteCommentInfonoteid(note_create_id);
        PageInfo<ViewNoteCommentInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //点击举报按钮将会把评论状态从正常修改为被举报
    @Override
    public Integer updateStatus(Integer note_comment_id) {
        return noteCommentMapper.updateStatus(note_comment_id);
    }

    //点赞
    @Override
    public Integer likeComment(Integer note_comment_id) {
        return noteCommentMapper.incrementLikeCount(note_comment_id);
    }

    //取消点赞
    @Override
    public Integer unlikeComment(Integer note_comment_id) {
        return noteCommentMapper.decrementLikeCount(note_comment_id);
    }

    //根据笔记id计数
    @Override
    public Integer countcomment( Integer note_create_id) {
        return noteCommentMapper.countcomment(note_create_id);
    }
}
